/**
 * Created by alex on 11.03.2015.
 */
/*function AngularCtrl($scope,$http){
    $scope.list;
    $.get('https://api.myjson.com/bins/3v5v3 ', function (response) {
        $scope.list = response;
        $scope.title1 = Object.keys($scope.list);
        $scope.$apply();
    });

}*/
function AngularCtrl($scope,$http) {

    $scope.list = [{
        "id": 1,
        "title": "1. dragon-breath",
        "items": []
    }, {
        "id": 2,
        "title": "2. moiré-vision",
        "items": [{
            "id": 21,
            "title": "2.1. tofu-animation",
            "items": [{
                "id": 211,
                "title": "2.1.1. spooky-giraffe",
                "items": []
            }, {
                "id": 212,
                "title": "2.1.2. bubble-burst",
                "items": []
            }]
        }, {
            "id": 22,
            "title": "2.2. barehand-atomsplitting",
            "items": []
        }]
    }, {
        "id": 3,
        "title": "3. unicorn-zapper",
        "items": []
    }, {
        "id": 4,
        "title": "4. romantic-transclusion",
        "items": []
    }];

    var i =0;
    var listok = [];
    function recursive(data)
    {
        if(typeof(data) === "object" && Object.keys(data).length > 1) {
                per(data);
            if( !(data.length))
                listok.push(data);
        }
        else {

        }
        /*if()
        {
            console.log("piu");
            var keys = Object.keys(data);
            $.each(keys, function(k,v) {
                recursive(v);
            });
        }
        else
        {
            console.log(data);
        }*/

    }



    function per(response) {
        var keys = Object.keys(response);
        $.each(keys, function(k,v)
        {
          //  console.log(response[k]);
           recursive(response[v]);
        });

    }


    $.get('https://api.myjson.com/bins/3v5v3 ', function (response) {
        per($scope.list);
        console.log(listok);
        $scope.$apply();
    });



/*   $scope.selectedItem = {};

            $scope.options = {
            };

            $scope.remove = function(scope) {
                scope.remove();
            };


            $scope.newSubItem = function(scope) {
                var nodeData = scope.$modelValue;
                nodeData.items.push({
                    id: nodeData.id * 10 + nodeData.items.length,
                    title: nodeData.title + '.' + (nodeData.items.length + 1),
                    items: []
                });
            };*/
        }

